<template>
  <!-- 底部 -->
  <div class="my-footer">
    <!-- 全选 -->
    <div class="custom-control custom-checkbox">
      <input
        type="checkbox"
        class="custom-control-input"
        id="footerCheck"
        :checked="all"
        @change="click1"
      />
      <label class="custom-control-label" for="footerCheck">全选</label>
    </div>
    <!-- 合计 -->
    <div>
      <span>合计:</span>
      <span class="price">¥ {{ allPrice }}</span>
    </div>
    <!-- 按钮 -->
    <button type="button" class="footer-btn btn btn-primary">
      结算 {{ allCount }}
    </button>
  </div>
</template>

<script>
import { mapGetters, mapMutations } from "vuex";
export default {
  props: ["item"],
  computed: {
    ...mapGetters("cart", ["allCount", "allPrice", "all"]),
    // 全选和单选
    // all: {
    //   set(val) {
    //     this.item.map((e) => {
    //       e.goods_state = val;
    //     });
    //   },
    // },
    // allPrice() {
    //   return this.item.reduce((sum, e) => {
    //     if (e.goods_state) {
    //       sum += e.goods_count * e.goods_price;
    //     }
    //     return sum;
    //   }, 0);
    // },
    // allCount() {
    //   return this.item.reduce((sum, e) => {
    //     if (e.goods_state) {
    //       sum += e.goods_count;
    //     }
    //     return sum;
    //   }, 0);
    // },
  },
  methods: {
    ...mapMutations("cart", ["setGoodsList"]),
    click1(e) {
      // console.log(e.target);
      // console.log(e.target.checked);
      this.setGoodsList(e.target.checked);
    },
  },
};
</script>

<style lang="less" scoped>
.my-footer {
  position: fixed;
  z-index: 2;
  bottom: 0;
  width: 100%;
  height: 50px;
  border-top: 1px solid #ccc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 10px;
  background: #fff;

  .price {
    color: red;
    font-weight: bold;
    font-size: 15px;
  }
  .footer-btn {
    min-width: 80px;
    height: 30px;
    line-height: 30px;
    border-radius: 25px;
    padding: 0;
  }
}
</style>